package com.kvw.filesystem.config;

import com.kvw.filesystem.util.PropertyUtils;
import lombok.Data;
import lombok.ToString;

import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * Desc:
 *
 * @author: keen
 * Date: 2020-07-18
 * Time: 13:00
 */
@Data
@ToString
public class MinioStorageConfig {
    private static final String MINIO_CONFIG_FILE_NAME = "minio.properties";
    private Properties properties;
    private String host;
    private int port = 9000;
    private String accessKey;
    private String secretKey;
    private String charset;
    private long partSize;
    private boolean secure;

    public MinioStorageConfig() {
        this(PropertyUtils.load(MinioStorageConfig.class.getClassLoader().getResourceAsStream(MINIO_CONFIG_FILE_NAME)));
    }

    public MinioStorageConfig(Properties properties) {
        this.properties = properties;
        init();
    }


    private void init() {
        this.host = PropertyUtils.getString(properties, "minio.host", "127.0.0.1");
        this.port = PropertyUtils.getInteger(properties, "minio.port", 9000);
        this.accessKey = PropertyUtils.getString(properties, "minio.accessKey");
        this.secretKey = PropertyUtils.getString(properties, "minio.secretKey");
        this.charset = PropertyUtils.getString(properties, "minio.charset", "UTF-8");
        this.secure = PropertyUtils.getBoolean(properties, "minio.secure", true);
    }

    public static MinioStorageConfig getDefaultMinioConfig() {
        return new MinioStorageConfig();
    }

}
